package com.houseService.service.controller;

import com.houseService.common.annotation.Log;
import com.houseService.common.core.controller.BaseController;
import com.houseService.common.core.domain.AjaxResult;
import com.houseService.common.enums.BusinessType;
import com.houseService.common.utils.poi.ExcelUtil;
import com.houseService.service.vo.ServicesVo;
import com.houseService.service.service.IServicesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.houseService.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 服务项目管理Controller
 *
 * @author Tellsea
 * @date 2025-03-19
 */
@Api(tags = "服务项目管理Controller")
@RestController
@RequestMapping("/service/service")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ServicesController extends BaseController {

    private final IServicesService servicesService;

    @ApiOperation("查询服务项目管理列表")
    @PreAuthorize("@ss.hasPermi('service:service:list')")
    @GetMapping("/list")
    public TableDataInfo<ServicesVo> list(ServicesVo entity) {
        return servicesService.queryList(entity);
    }

    @ApiOperation("查询服务项目管理所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(ServicesVo entity) {
        return AjaxResult.success("查询成功", servicesService.queryAll(entity));
    }

    @ApiOperation("导出服务项目管理列表")
    @PreAuthorize("@ss.hasPermi('service:service:export')")
    @Log(title = "服务项目管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServicesVo entity) {
        List<ServicesVo> list = servicesService.queryAll(entity);
        ExcelUtil<ServicesVo> util = new ExcelUtil<>(ServicesVo.class);
        util.exportExcel(response, list, "服务项目管理数据");
    }

    @ApiOperation("获取服务项目管理详细信息")
    @PreAuthorize("@ss.hasPermi('service:service:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success("查询成功", servicesService.queryById(id));
    }

    @ApiOperation("新增服务项目管理")
    @PreAuthorize("@ss.hasPermi('service:service:add')")
    @Log(title = "服务项目管理", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody ServicesVo entity) {
        return toAjax(servicesService.save(entity));
    }

    @ApiOperation("修改服务项目管理")
    @PreAuthorize("@ss.hasPermi('service:service:edit')")
    @Log(title = "服务项目管理", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody ServicesVo entity) {
        return toAjax(servicesService.updateById(entity));
    }

    @ApiOperation("删除服务项目管理")
    @PreAuthorize("@ss.hasPermi('service:service:remove')")
    @Log(title = "服务项目管理", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(servicesService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
